home *** CD-ROM | disk | FTP | other *** search
- /*
- TransSkel demonstration: Traditional Skel
-
- This program mimics the original Skel application: one sizable,
- dragable, non-closable dark gray window, an "About" alert and two
- dialogs. Desk accessories supported.
-
- The project should include this file, TransSkel.c (or a project
- built from TransSkel.c), and MacTraps.
-
- 27 June 1986 Paul DuBois
- */
-
- # include <DialogMgr.h> /* includes WindowMgr, QuickDraw, etc. */
- # include <MenuMgr.h>
- # include <ToolboxUtil.h>
-
- # define nil 0L
-
- /*
- Resource numbers
- */
-
- # define fileMenuRes 2 /* File menu */
- # define aboutAlrt 1000 /* About box */
- # define theWindRes 260 /* window */
- # define reportDlog 257 /* message dialog box */
- # define aboutStr 1 /* message strings */
- # define rattleStr 2
- # define frightStr 3
-
-
-
- /* file menu item numbers */
-
- typedef enum {
- rattle = 1,
- frighten,
- /* --- */
- quit = 4
- } fileItems;
-
-
- WindowPtr theWind;
-
- /*
- Menu handles. There isn't any apple menu here, since TransSkel will
- be told to handle it itself.
- */
-
- MenuHandle fileMenu;
-
-
- /* -------------------------------------------------------------------- */
- /* Menu handling procedures */
- /* -------------------------------------------------------------------- */
-
-
- /*
- Read a string resource and put into the Alert/Dialog paramtext
- values
- */
-
- SetParamText (strNum)
- int strNum;
- {
- StringHandle h;
-
- h = GetString (strNum);
- HLock (h);
- ParamText (*h, "\p", "\p", "\p");
- HUnlock (h);
- }
-
-
- /*
- Handle selection of "About Skel…" item from Apple menu
- */
-
- DoAbout ()
- {
- StringHandle h;
-
- SetParamText (aboutStr);
- (void) Alert (aboutAlrt, nil);
- }
-
-
- /*
- Put up a dialog box with a message and an OK button. The message
- is stored in the 'STR ' resource whose number is passed as strNum.
- */
-
- Report (strNum)
- int strNum;
- {
- DialogPtr theDialog;
- int itemHit;
-
- SetParamText (strNum);
- theDialog = GetNewDialog (reportDlog, nil, -1L);
- ModalDialog (nil, &itemHit);
- DisposDialog (theDialog);
- }
-
-
- /*
- Process selection from File menu.
-
- Rattle, Frighten A dialog box with message
- Quit Request a halt by calling SkelHalt(). This makes SkelMain
- return.
- */
-
- DoFileMenu (item)
- int item;
- {
-
- switch (item)
- {
- case rattle: Report (rattleStr); break;
- case frighten: Report (frightStr); break;
- case quit: SkelWhoa (); break; /* request halt */
- }
- }
-
-
- /*
- Initialize menus. Tell TransSkel to process the Apple menu
- automatically, and associate the proper procedures with the
- File and Edit menus.
- */
-
- SetUpMenus ()
- {
-
- SkelApple ("\pAbout Skel…", DoAbout);
- fileMenu = GetMenu (fileMenuRes);
- SkelMenu (fileMenu, DoFileMenu, nil);
- }
-
-
- /* -------------------------------------------------------------------- */
- /* Window handling procedures */
- /* -------------------------------------------------------------------- */
-
-
- WindActivate (active)
- Boolean active;
- {
-
- DrawGrowIcon (theWind); /* make grow box reflect new window state */
- }
-
-
- /*
- On update event, can ignore the resizing information, since the whole
- window is always redrawn in terms of the current size, anyway.
- Content area is dark gray except scroll bar areas, which are white.
- Draw grow box as well.
- */
-
- WindUpdate (resized)
- Boolean resized;
- {
- Rect r;
-
- r = theWind->portRect; /* paint window dark gray */
- r.bottom -= 15; /* don't bother painting the */
- r.right -= 15; /* scroll bar areas */
- FillRect (&r, dkGray);
- r = theWind->portRect; /* paint scroll bar areas white */
- r.left = r.right - 15;
- FillRect (&r, white);
- r = theWind->portRect;
- r.top = r.bottom - 15;
- FillRect (&r, white);
- DrawGrowIcon (theWind);
- }
-
-
- WindHalt () { CloseWindow (theWind); }
-
-
- /*
- Read window from resource file and install handler for it. Mouse
- and key clicks are ignored. There is no close proc since the window
- doesn't have a close box. There is no idle proc since nothing is
- done while the window is in front (all the things that are done are
- handled by TransSkel).
- */
-
- WindInit ()
- {
-
- theWind = GetNewWindow (theWindRes, nil, -1L);
- SetPort (theWind);
- SkelWindow (theWind, nil, nil, WindUpdate, WindActivate, nil,
- WindHalt, nil, false);
- }
-
-
- /* -------------------------------------------------------------------- */
- /* Main */
- /* -------------------------------------------------------------------- */
-
-
- main ()
- {
-
- SkelInit (); /* initialize */
- SetUpMenus (); /* install menu handlers */
- WindInit(); /* install window handler */
- SkelMain (); /* loop 'til Quit selected */
- SkelClobber (); /* clean up */
- }
-